/** @file MainPage.qml
@brief The start page of the application. Shows the splash screen and start with the main
application toolbar.

This main page access to the main view of the applicaiton focused on the design management of
the svg objects. From the main toolbar the page access to the design toolbar or move to the other secondary pages.
Every page is coded following a specific colour.

@authorname \n
@licenseversion \n
@actualversion - @dateupdate

@licensenote
*/

import QtQuick 1.0
import com.nokia.symbian 1.0
import "QtComplex" as Framework
import "QtComplex/Theme.js" as Theme
import "QtComplex/Geometry.js" as Geometry
import "QtComplex/Tools.js" as QTCtools
import "BlackCat.js" as BCCS

Page {
    id: mainPage
    tools: commonTools

    Framework.ComplexItem {
        id: qtComplex
        theme: "bccs"
        screenCategory: screen.displayCategory;
    }

    // Background
    Rectangle {
        id: background

        width: mainPage.width
        height: mainPage.height
        color: QTCtools.light
    }

    // Background
    // This object is needed to animate the second level toolbar.
    Rectangle {
        id: toolbar_background
        width: mainPage.width
        height: QTCtools.getToolbarHeight(parent.height)
    }

    MainToolbar {
        id: main_tb
        width: parent.width
        height: parent.height
        anchors.top: parent.top

        onToolbarEvent: {
            console.log("Clicked button "+ button)
            // Button 1 hide the drawing toolbar
            if (button == 1) {
                if (draw_tb_container.state == "Show") {
                    draw_tb_container.state = "Hide";
                    console.log("Hide drawing toolbar");
                }
            }
            // Button 2 show the drawing toolbar
            if (button == 2) {
                if (draw_tb_container.state == "Hide") {
                    draw_tb_container.state = "Show";
                    console.log("Show drawing toolbar");
                }
            }
            if (button == 7)
                BCCS.openFile("HelpPage.qml");
        }

    }

    Item {
        id: draw_tb_container
        width: parent.width
        height: parent.height
        anchors.bottom: mainPage.top

        state: "Hide"

        DrawToolbar {
            id: draw_tb
            width: parent.width
            height: parent.height
        }

        states: [
            State {
                name: "Show"
                    AnchorChanges { target: draw_tb_container;
                    anchors.top: toolbar_background.bottom
                    anchors.bottom: undefined }
            },
            State {
                name: "Hide"
                AnchorChanges { target: draw_tb_container;
                    anchors.bottom: mainPage.top
                    anchors.top: undefined }
            }
        ]

        // The states transition are defined reversible to be reused to show and hide the object
        transitions: [
            Transition {
                from: "Show"; to: "Hide"
                reversible: true
                AnchorAnimation { easing.type: Easing.InQuad; duration: BCCS.animDuration; }
            }
        ]
    }

    // Load a custom splash screen using the ShowSplash method
    Framework.ShowSplash {
        id: splashScreen
        width: parent.width
        height: parent.height
        customSplash: "themes/bccs/Splash.qml"
        slpashAnimDuration: BCCS.animSplash
        waitDuration: BCCS.waitSplash
    }
}
